package fmi.chesstern.controller.implementation;

import java.util.HashMap;
import java.util.Map;


import fmi.chesstern.controller.GameCommand;
import fmi.chesstern.controller.GameCommandExecutor;
import fmi.chesstern.controller.GameCommandParameters;
import fmi.chesstern.controller.GameCommandType;
import fmi.chesstern.game.GameState;

public class DefaultGameCommandExecutor implements GameCommandExecutor {
	private GameState gameState;
	private Map<GameCommandType, GameCommand> commandTypeToCommand;
	
	public DefaultGameCommandExecutor(GameState state) {
		this.gameState = state;
		commandTypeToCommand = new HashMap<GameCommandType, GameCommand>();
	}
	
	public void registerCommand(GameCommandType type, GameCommand command) {
		commandTypeToCommand.put(type, command);
	}
	
	public void executeCommand(GameCommandType type, GameCommandParameters parameters) {
		if (commandTypeToCommand.containsKey(type)) {
			commandTypeToCommand.get(type).execute(gameState, parameters);
		}
	}
}
